package com.hjq.mallproduct.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

//import org.apache.shiro.authz.annotation.RequiresPermissions;
import com.hjq.mallproduct.entity.ProductAttrValueEntity;
import com.hjq.mallproduct.entity.vo.AttrResponseVO;
import com.hjq.mallproduct.entity.vo.AttrVO;
import com.hjq.mallproduct.service.ProductAttrValueService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.hjq.mallproduct.service.AttrService;
import com.hjq.common.utils.PageUtils;
import com.hjq.common.utils.R;



/**
 * 商品属性
 *
 * @author Hjq
 * @email 1484397309@qq.com.com
 * @date 2022-05-24 14:18:33
 */
@RestController
@RequestMapping("mallproduct/attr")
public class AttrController {
    @Autowired
    private AttrService attrService;
    @Autowired
    private ProductAttrValueService attrValueService;


    @RequestMapping("/base/listforspu/{spuId}")
    //@RequiresPermissions("mallproduct:attr:list") base/list/0
    public R baseAttrList(@PathVariable("spuId") Long spuId){
        List<ProductAttrValueEntity> attrValueList=attrValueService.getAttrListOfSpu(spuId);
        return R.ok().put("data",attrValueList);
    }
    /**
     * 列表/product/attr/base/listforspu/{spuId}
     */
    @RequestMapping("/{type}/list/{catId}")
    //@RequiresPermissions("mallproduct:attr:list") base/list/0
    public R list(@RequestParam Map<String, Object> params,
                  @PathVariable("catId") Long categoryId,
                  @PathVariable("type") String type){

        PageUtils   page = attrService.queryBasePage(params,categoryId,type);


        return R.ok().put("page", page);
    }
    /**
     * 列表
     */
    @RequestMapping("/list")
    //@RequiresPermissions("mallproduct:attr:list") base/list/0
    public R list2(@RequestParam Map<String, Object> params){
        PageUtils page = attrService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{attrId}")
    //@RequiresPermissions("mallproduct:attr:info")
    public R info(@PathVariable("attrId") Long attrId){
		AttrResponseVO attr = attrService.getAttrInfoWithCatWholePath(attrId);

        return R.ok().put("attr", attr);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    //@RequiresPermissions("mallproduct:attr:save")
    public R save(@RequestBody AttrVO attr){
		attrService.saveAttrByVO(attr);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
   // @RequiresPermissions("mallproduct:attr:update")
    public R update(@RequestBody AttrVO  attr){
		attrService.updateAttrByVO(attr);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
   // @RequiresPermissions("mallproduct:attr:delete")
    public R delete(@RequestBody Long[] attrIds){
		attrService.removeByIds(Arrays.asList(attrIds));

        return R.ok();
    }

}
